﻿/*
=======================================================
    RegulatorUser【监管部门用户】
=======================================================
*/

namespace Services
{
    public interface IRegulatorUserRepository : IRepository<RegulatorUser>
    {
        int UpdateIsDelete(bool flag, int[] ids);
        void ResetPassword(List<int> ids, string pwd);
        bool GetLoginNameExists(string loginName, int regulatorID);
    }


    public class RegulatorUserRepository : BaseRepository<RegulatorUser>, IRegulatorUserRepository
    {
        public RegulatorUserRepository(ISqlSugarClient dB, ICurrentUser currentUser, IQuery<RegulatorUser> query)
            : base(dB, currentUser, query)
        {
        }

        #region 启用/禁用  UpdateIsDelete
        public int UpdateIsDelete(bool flag, int[] ids)
        {
            return _DB.Updateable<RegulatorUser>()
                      .SetColumns(x => new RegulatorUser { IsDelete = flag })
                      .Where(x => ids.Contains(x.RegulatorUserID))
                      .ExecuteCommand();
        }
        #endregion

        #region 重置密码  ResetPassword
        public void ResetPassword(List<int> ids, string pwd)
        {
            _DB.Updateable<RegulatorUser>().SetColumns(x => x.LoginPassword == pwd)
                .Where(x => ids.Contains(x.RegulatorUserID))
                .ExecuteCommand();
        }
        #endregion

        #region GetLoginNameExists
        public bool GetLoginNameExists(string loginName, int regulatorID)
        {
            return _query.GetQueryable().Where(x => x.LoginName == loginName && x.RegulatorID == regulatorID).Count() > 0;
        } 
        #endregion
    }
}
